/**
 * 请求接口模块
 */
const BASEURL = 'http://www.gyxz.com'
/* 登录操作 */
export const loginAjax = ({ phone, password }) => {
	wx.showLoading({ title: '登录中' })
	return new Promise((resolve, reject) => {
		wx.request({
			url: `${BASEURL}/yh/${phone}-${password}`,
			method: 'GET',
			success(res) {
				wx.hideLoading()
				resolve(res.data)
			},
			fail(error) {
				reject(error)
			}
		})
	})
}
/* 提交选座 */
export const submitSeatAjax = (obj) => {
	wx.showLoading({
		title: '预定中',
	})
	return new Promise((resolve, reject) => {
		wx.request({
			url: `${BASEURL}/yuyue/${obj.type}-${obj.zw}-${obj.starttime}-${obj.endtime}-${obj.username}-${obj.phone}-${obj.cz}`,
			method: 'GET',
			success(res) {
				wx.hideLoading()
				if (res.data.msg === 'ok') {
					resolve(true)
				} else {
					resolve(false)
				}
			}
		})
	})
}
/* 修改密码 */
export const resetPassAjax = ({ phone, newmm }) => {
	wx.showLoading({ title: '修改中' })
	return new Promise((resolve, reject) => {
		wx.request({
			url: `${BASEURL}/resetmm/${phone}-${newmm}`,
			success: (res) => {
				setTimeout(() => {
					wx.hideLoading()
					if (res.data.msg === 'ok') resolve(true)
					else resolve(false)
				}, 6000)
			},
			fail: () => {
				wx.hideLoading()
				wx.showToast({ title: '请求超时', icon: 'error', duration: 2000 })
			}
		})
	})
}
/* 获取我的选座列表 */
export const getMySeatsAjax = (phone) => {
	return new Promise((resolve, reject) => {
		wx.request({
			url: `${BASEURL}/yuyues/${phone}`,
			success: (res) => {
				resolve(res.data)
			}
		})
	})
}
/* 取消预约操作 */
export const cancelReservation = (id) => {
	return new Promise((resolve, reject) => {
		wx.request({
			url: `${BASEURL}/cacelyuyue/${id}`,
			success: (res) => {
				if (res.data.msg === 'ok') resolve(true)
				else resolve(false)
			}
		})
	})
}